<?php
/**
 * Created by PhpStorm.
 * User: 戎大富
 * Date: 2019/5/14
 * Time: 14:07
 */
namespace app\home\controller;
use think\Db;
class Renovation extends Base {

    public function index(){
        $data = Db::name('company')
            ->paginate(8);
        $where['lb_status'] = 1;
        $where['lb_type'] = 1;
        $banner = Db::table('up_lunbo')->where($where)->select();
        $this->assign('banner',$banner);
        $this->assign('data',$data);
        return $this->fetch();
    }
    //
    public function detail(){
        $id = input('param.id');
        $data = Db::table('up_company')->where('id',$id)->find();
        $img= explode(',',$data['image']);
        $this->assign('imgData',$img);
        $this->assign('data',$data);
//
        $designs = Db::table('up_u_user')
            ->where('user_type',3)
            ->where('user_status',1)
            ->where('user_company_id_3',$data['id'])
            ->order('user_reject_time DESC')
            ->field('user_id,user_username,user_shop,user_image,user_phone,user_year_3,user_cases_3,user_ercode')
            ->page(1,10)
            ->select();
        $this->assign('designs',$designs);
        return $this->fetch();
    }
    /**
     * 案例
     *
     */
    public function cases(){
        $data = Db::name('company_case')
            ->paginate(8);
        $where['lb_status'] = 1;
        $where['lb_type'] = 1;
        $banner = Db::table('up_lunbo')->where($where)->select();
        $this->assign('banner',$banner);
        $this->assign('data',$data);
        return $this->fetch();
    }
    /**
     * 案例详情
     */
    public function casedetail()
    {
        extract(input());
        $data = Db::table('up_company_case')->alias('cc')
            ->join ('up_u_user u','cc.cc_u_id = u.user_id','LEFT')
            ->where('cc_id',$cc_id)
            ->field('cc.*,user_id,user_username,user_shop,user_image,user_phone,user_ercode')
            ->find();
        if($data['cc_image']){
            $data['cc_image'] = explode(',',$data['cc_image']);
        }
        $this->assign('data',$data);
        return $this->fetch();
    }
    /**
     * 设计师
     */
    public function designs(){
        $where = [
            'user_type' => 3 ,
            'user_status' => 1
        ];
        $data = Db::table('up_u_user')
            ->where($where)
            ->order('user_time DESC')
            ->field('user_id,user_username,user_shop,user_image,user_phone,user_year_3,user_cases_3,user_ercode')
            ->paginate(6);
        $where = [];
        $where['lb_status'] = 1;
        $where['lb_type'] = 1;
        $banner = Db::table('up_lunbo')->where($where)->select();
        $this->assign('banner',$banner);
        $this->assign('data',$data);
        return $this->fetch();
    }
    /**
     * 设计师详情
     */
    public function design_detail(){
        $uid = input('uid');
        $user_id = session('user_id');
        $field = 'user_id,user_username,user_shop,user_image,user_phone,user_year_3,user_cases_3,user_signs_3,user_content_3';
        $field .= ',user_chengjiao,user_fuwu,user_fen,user_ercode';
        $data = Db::table('up_u_user')
            ->where('user_id',$uid)
            ->field($field)
            ->find();
        if($data['user_signs_3']){
            $data['user_signs_3'] = explode(',',$data['user_signs_3']);
        }else{
            $data['user_signs_3'] = [];
//            $data['user_signs_3'] = [$data['user_year_3'] . '年经验'];
        }
        $have = Db::table('up_like_design')
            ->where('like_user_id',$user_id)
            ->where('like_user_id_3',$uid)
            ->find ();
        $like = 0;
        if($have){
            $like = 1;//已关注
        }
        //
        $cases = Db::table('up_company_case')
            ->where('cc_u_id',$uid)
            ->order('cc_time DESC')
            ->field('cc_id,cc_title,cc_name,cc_thumb')
            ->page(1,6)
            ->select();
        $this->assign('like',$like);
        $this->assign('cases',$cases);
        $this->assign('data',$data);
        return $this->fetch();
    }
}